package com.top.ruizhong.main.access

import androidx.lifecycle.Observer
import com.blankj.utilcode.util.LogUtils
import com.module.lemlin.mode.ViewModeFragment
import com.top.ruizhong.R
import com.top.ruizhong.mode.vm.AccessViewModel
import kotlinx.android.synthetic.main.fragment_access_bind.*

class BindFragment : ViewModeFragment<AccessViewModel>() {

    companion object {
        fun newInstance(): BindFragment {
            return BindFragment()
        }
    }

    override val layoutResId: Int
        get() = R.layout.fragment_access_bind

    override fun viewModel(): AccessViewModel {
        return createViewModel(requireActivity())
    }

    override fun initView() {
        viewModel.observableEditText(etBindMobileContent)
    }

    override fun initViewMode() {
        viewModel.contentMobileBindLiveData.observe(viewLifecycleOwner, Observer { mobile ->
            tvBindGetCode.isEnabled = !(mobile.isNullOrEmpty() || mobile.length != 11)
        })
    }

    override fun onDestroy() {
        super.onDestroy()
        viewModel.clearLiveDataMobileBind()
    }
}